package data.platform.common.stream.valueobjects;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
public class RuleMetricCondition {

    private String metric;

    private AggregatorFunctionType aggregatorFunctionType;

    private LimitOperatorType limitOperatorType;

    private Double limit;

    public boolean apply(Double comparisonValue) {
        switch (limitOperatorType) {
            case EQUAL:
                return comparisonValue.compareTo(limit) == 0;
            case NOT_EQUAL:
                return comparisonValue.compareTo(limit) != 0;
            case GREATER:
                return comparisonValue.compareTo(limit) > 0;
            case LESS:
                return comparisonValue.compareTo(limit) < 0;
            case LESS_EQUAL:
                return comparisonValue.compareTo(limit) <= 0;
            case GREATER_EQUAL:
                return comparisonValue.compareTo(limit) >= 0;
            default:
                throw new RuntimeException("Unknown limit operator type: " + limitOperatorType);
        }
    }

    @Override
    public String toString() {
        return "RuleMetricCondition{" +
                "metric='" + metric + '\'' +
                ", aggregatorFunctionType=" + aggregatorFunctionType +
                ", limitOperatorType=" + limitOperatorType +
                ", limit=" + limit +
                '}';
    }
}
